<?php namespace Common\Model;
use Hdphp\Model\Model;

class Order extends Model{
	protected $table='orderform';
	//声明自动完成来添加没有的字段
	protected $auto=array(
		array('orderid','orderid','method',3,1),
		array('maketime','time','function',3,1),
	);
	//声明自动完成的方法
	protected function orderid(){
		return Cart::getOrderId();
	}
	public function store($post,$sebox){
		//将获得的数据进行整合，然后添加到对里面去
//		p($post);
//		p($sebox);exit;
		$this->data=$post;
		//对订单表的添加
		if($this->create()){
			$this->data['homeuser_uid']=$_SESSION['uid'];	
			$this->data['totalprice']=$sebox['total'];	
			$oid=$this->add();
		}	
		//对订单列表的添加	
		//1.sebox的数组从新组合
		foreach ($sebox['goods'] as $k => $v) {
			$sebox['goods'][$k]['options']=implode(',', $v['options']);
			$sebox['goods'][$k]['orderform_oid']=$oid;
		}
//		p($sebox);
		$model=M('\Common\Model\Orderlist');
		foreach ($sebox['goods'] as $v) {
			//对模型的data添加对应的字段，以便能直接用add添加到订单列表里面去
			$model->data['spec']=$v['options'];
			$model->data['number']=$v['num'];
			$model->data['allprice']=$v['total'];
			$model->data['orderform_oid']=$v['orderform_oid'];
			$model->data['goods_gid']=$v['id'];
			$model->data['goodimg']=$v['img'];
			$model->data['goodname']=$v['name'];
//			p($model->data);
			//对商品列表的添加
			$model->add();
		}
		
//		p($this->data);exit;
		//整合所需要的字段添加到			
		return $oid;
	}

}
?>